<?
session_start();
include "connectdb.php" ;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ยินดีต้อนรับเข้าสู่ ระบบบริการสื่อมัลติมีเดียด้านการเกษตร</title>
<link rel="stylesheet" href="standard.css" type="text/css" />
<script>  
	function txtreset()
		{
		document.frmSearch.txtkeyword.value="";
		}
</script>
<?php 
function remember(){

		for ($i=0;$i<count($_GET["cb_array"]);$i++) {
				$cb_array = $cb_array[$i];
			}
			
}
?>


<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<script type="text/javascript">    
function setPic(imgShow){   
    var showBig=document.getElementById('bigGallDiv');   
    showBig.style.display='block';   		
	showBig.style.visibility='hidden';   
    showBig.innerHTML="<img src='"+imgShow+"' title='คลิกที่รูปเืพื่อปิด' >";   
	setTimeout("showPic()",500);
} 
function  showPic(){
	var showBig=document.getElementById('bigGallDiv');   
    var LeftVal=0;   	
    if(showBig.innerHTML!=""){   
		LeftVal=showBig.offsetWidth;      					
		LeftVal=(gWH().width-LeftVal)/2;   	
    }   
	showBig.style.left=LeftVal+"px";   
	showBig.style.visibility='visible';   	
}
function gWH(){ // ฟังก์ชันหาความกว้างและความสูงของหน้าเพจ   
    var e = window, a = 'inner';   
    if ( !( 'innerWidth' in window ) ){   
        a = 'client';   
        e = document.documentElement || document.body;   
    }   
    return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }   
}  
</script>
</head>

<body onLoad="MM_preloadImages('img/m_main2.jpg','img/m_register2.jpg','img/m_multimedia2.jpg','img/m_manual2.jpg','img/m_evaluate2.jpg','img/m_admin2.jpg','img/m_static2.jpg','img/m_topten2.jpg')">
<table width="1024" height="659" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#666600">
  <tr>
    <td height="215" align="center" valign="top" bgcolor="#CCCCCC"><table width="1024" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="170" background="img/headNew2.jpg" bgcolor="#FFFFFF">&nbsp;</td>
      </tr>
    </table>
        <table width="824" border="0" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
          <tr>
            <td width="103" height="45" align="center"><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image12','','img/m_main2.jpg',1)"><img src="img/m_main.jpg" name="Image12" width="115" height="45" border="0" id="Image12" /></a></td>
            <td width="103" align="right"><a href="user_register.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image13','','img/m_register2.jpg',1)"><img src="img/m_register.jpg" name="Image13" width="115" height="45" border="0" id="Image13" /></a></td>
            <td width="103" align="right"><a href="vdo_list.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image14','','img/m_multimedia2.jpg',1)"><img 
src="img/m_multimedia.jpg" name="Image14" width="117" height="45" border="0" id="Image14" /></a></td>
            <td width="103"><a href="vdo_top10.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image11','','img/m_topten2.jpg',1)"><img 
src="img/m_topten.jpg" name="Image11" width="115" height="45" border="0" id="Image11" /></a></td>
            <td width="103"><a href="admin_report_search.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image10','','img/m_static2.jpg',1)"><img 
src="img/m_static.jpg" name="Image10" width="215" height="45" border="0" id="Image10" /></a></td>
            <td width="103"><a href="manual.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image9','','img/m_manual2.jpg',1)"><img src="img/m_manual.jpg" name="Image9" width="117" height="45" border="0" id="Image9" /></a></td>
            <td width="103"><a href="evaluate_overview.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image8','','img/m_evaluate2.jpg',1)"><img src="img/m_evaluate.jpg" name="Image8" width="115" height="45" border="0" id="Image8" /></a></td>
            <td width="103"><a href="admin_login.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image15','','img/m_admin2.jpg',1)"><img src="img/m_admin.jpg" name="Image15" width="115" height="45" border="0" id="Image15" /></a></td>
          </tr>
        </table></td>
  </tr>
  <tr>
    <td width="1024" height="66" align="center" valign="top" bgcolor="#FFFFFF"><table width="1024" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="25" height="25" background="img/tb/tb_left_top.jpg">&nbsp;</td>
        <td height="25" background="img/tb/tb_top.jpg">&nbsp;</td>
        <td width="25" height="25" background="img/tb/tb_right_top.jpg">&nbsp;</td>
      </tr>
      <tr>
        <td width="25" align="left" background="img/tb/tb_left.jpg">&nbsp;</td>
        <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="30" align="left" bgcolor="#CCFF00" class="style7"><span class="scapmain style7">&nbsp;<img src="img/img05.gif" align="absbottom" /></span> 10 อันดับสูงสุด</td>
			<td align="right" bgcolor="#CCFF00" class="style7">
<? if(isset($_SESSION["sess_user_register"])){echo"<a href="."user_logout.php"."><img src="."pic/logout(red)_icon.jpeg"." width='30' alt='ออกจากระบบ' border='0'/></a>";} ?></td>
            <td align="right" bgcolor="#CCFF00" class="style7"><? if(isset($_SESSION["sess_Username"])){echo"<a href="."admin_logout.php"."><img src="."pic/logout(red)_icon.jpeg"." width='30' alt='ออกจากระบบ' border='0'/></a>";} ?></td>
          </tr>
          <tr>
            <td colspan="2" align="center" bgcolor="#FFFFFF"><table width="50%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="30">&nbsp;</td>
              </tr>
            </table>
              <table width="98%" height="247" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get" name="frmSearch" id="frmSearch" onsubmit="">
                              <tr>
                                <td height="40" align="center" valign="middle" bgcolor="#CCFF00"><span class="style24">เลือกรายการ 10 อันดับ</span> 
                                  <select name="txtfield" id="txtfield" >
                                    <option value="1" <? if($_GET["txtfield"] == '1') echo"selected" ?>>10อันดับผู้ชมสูงสุด</option>
                                    <option value="2" <? if($_GET["txtfield"] == '2') echo"selected" ?>>10อันดับผู้ลงคะแนนสูงสุด</option>
                                    <option value="3" <? if($_GET["txtfield"] == '3') echo"selected" ?>>10อันดับสื่อมัลติมีเดียมาใหม่</option>
                                  </select>
                                  &nbsp;
                                  &nbsp;
                                <input type="submit" name="button" id="button" value="ตกลง" /></td>
                              </tr>
                            </form>
                        </table>
                            <? 
				  
						  
include "connectdb.php" ;
$SQL_TOPVIEWER = "SELECT * FROM ag_vdodetail ORDER BY vdo_view DESC limit 10; ";
$SQL_TOPRATE   = "SELECT * FROM ag_vdodetail ORDER BY (vdo_votesum/vdo_votecount) desc , vdo_votecount desc limit 10";
$SQL_TOPNEWSET = "SELECT * FROM ag_vdodetail ORDER BY vdo_dateadd desc limit 10; ";	

mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้"); /* ทําการเลือกฐานขอมูลกอน */ 
$sql="SELECT * FROM ag_vdodetail ORDER BY vdo_view DESC limit 10; ";  //DEFAULT

if($_GET["txtfield"]=="1"){
$sql = $SQL_TOPVIEWER; 
}else if ($_GET["txtfield"]=="2"){
$sql = $SQL_TOPRATE; 
}else if ($_GET["txtfield"]=="3"){
$sql = $SQL_TOPNEWSET; 
}

$db_query=mysql_db_query($dbname,$sql); 
//$num_rows=mysql_num_rows($db_query); /* นับ Reccord ทีพบ */





/*                          echo"<table width='100%' height='45' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#999999' bgcolor='#E8AD35'>";
                          echo"<tr>";
						  echo"<td width='50' class='style22'><div align='center' class='style24'>อันดับ</div></td>";
                          echo"<td width='50' class='style22'><div align='center' class='style24'>หมวด</div></td>";
                          echo"<td width='' class='style22'><div align='center' class='style24'>รายการ</div></td>";
                          echo"<td width='50' class='style22'><div align='center' class='style24'>จำนวน<br />ผู้ใช้บริการ</div></td>";
                          echo"<td width='87' class='style22'><div align='center' class='style24'>เรทติ้ง</div></td>";
                          echo"<td width='50' class='style22'><div align='center' class='style24'>จำนวน<br />ผู้โหวต</div></td>";
                          echo"</tr>";
                          echo"</table>";*/
                        
?>
                            <span class="style19 style19">
                            <?  ///////////////// วน loop แสดงข้อมูล //////////////////////

$a=0; 
$i=1; 
$colorzero="#FFF2A4";
$colorone="#FEE86E";
$bgcolor="";
$vdo_icon = "wmv_icon.gif";
$sound_icon = "wma_icon.jpg";
$unknow_icon = "unknow_icon.jpg";
//while($a < $num_rows) 
while($result = mysql_fetch_array($db_query)) 
{ 
//$result = mysql_fetch_array($db_query); 

$vdo_id=			$result[vdo_id];
$vdo_series_name=	$result[vdo_series_name];
$vdo_name=			$result[vdo_name];
$vdo_desc=			$result[vdo_desc];
$vdo_author=		$result[vdo_author];
$vdo_year=			$result[vdo_year];
$vdo_cover=			$result[vdo_cover];
$vdo_length=		$result[vdo_length];
$vdo_view=			$result[vdo_view];
$vdo_dateadd=		$result[vdo_dateadd];
$vdo_keyword=		$result[vdo_keyword];
$vdo_keyword_array = array();
$vdo_keyword_array=explode(",",$vdo_keyword);
$mediatype=$result[media_typeid];

if($mediatype==1){
	$vdo_pic=$vdo_icon;
} else if($mediatype==2){
	$vdo_pic=$sound_icon;
}else $vdo_pic=$unknow_icon;
//$vdo_view=$result[vdo_name]; 
$_SESSION["sess_Url"]=$result[vdo_url]; 

//$SQL_SELECT_RATING="SELECT * FROM ag_vdodetail where vdo_id = $vdo_id";
//$db_query_rating=mysql_db_query($dbname,$SQL_SELECT_RATING); 
//$result_rating = mysql_fetch_array($db_query_rating); 
$votesum=$result[vdo_votesum]; 
$votecount=$result[vdo_votecount]; 

if($votesum==0 and $votecount==0){
$rating=0;
$votecount=0;
} else $rating = $votesum/$votecount;
////////// ปัดเศษทศนิยม ถ้าน้อยกว่า 0.5 ให้ปัดลง 0.5-0.75 ให้ปัดลงเศษ 0.5 ถ้า 0.75-1 ให้ปัดขึ้น //////////
		if(($rating-(int)$rating)>=0.5 and ($rating-(int)$rating)<0.75)
		{$rating++;
		$rating=(int)$rating-0.5;
		}
		else if(($rating-(int)$rating)>=0.75 and ($rating-(int)$rating)<1)
		{
		$rating++;
		$rating=(int)$rating;
		}
		else $rating=(int)$rating;
//////////////////////////////จบการปัดเศษ//////////////////////////////
if (($a % 2) == 0) {
$bgcolor=$colorzero;
}
else $bgcolor=$colorone;

//========== vdo ใหม่จะไม่เกิน 4 อาทิตย์ นับจากวันที่เพิ่มข้อมูลลงไป ===========//
$today = Date("Y/m/d");
$str = $vdo_dateadd;  
list($year,$month,$day) = explode("/",$str);  
$mydate = (int)($year.$month.$day);
//echo "$mydate";  

//echo'<br>';
$SQL_SELECT_DAY = "SELECT DATEDIFF(curdate(),vdo_dateadd) FROM ag_vdodetail where vdo_id = '$vdo_id' ";
$resultday = mysql_query($SQL_SELECT_DAY);
$resultday2 = mysql_result($resultday,0);

$str = $today;  
list($year2,$month2,$day2) = explode("/",$str); 
$today =  (int)($year2.$month2.$day2);
//echo "$today";  
//================================================================//
////////////ตรวจสอบว่ามีการทำแบบประเมินหรือไม่//////////////////////
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้"); /* ทําการเลือกฐานขอมูลกอน */ 
$sql_eva="SELECT * FROM ag_evaluate_vdoans WHERE vdo_id = $vdo_id ;"; 
$db_query_eva=mysql_db_query($dbname,$sql_eva);  
$num_rows_eva=mysql_num_rows($db_query_eva); /* นับ Reccord ทีพบ */
	if (empty($num_rows_eva)){
	$evalink = "";
	}else $evalink = "<img src='pic/eva_result.gif' width='16' height='16' border='0' />";
////////////////////จบการตรวจสอบ/////////////////////////////
if($vdo_cover == ""){$vdo_cover = "pic/no_image.gif";}
?>
                            </span>
                            <table width="99%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td width="22%" rowspan="8" align="center"><div class="bigGallPic" id="bigGallDiv" onclick="this.style.display='none'"></div>
                                  <a href="javascript:setPic('<?=$vdo_cover?>');"><img src="<?=$vdo_cover?>" border="0" width="150" height='150' hspace='5' vspace='5' /></a></td>
                                <td height="20" align="left" class="style28"><span class="style8">หมายเลข :</span><span class="style24"> <? echo $vdo_id;?></span></td>
                                <td width="35%" height="20" align="left" class="style28"><span class="style8">หมวดหมู่</span><span class="style8"> : </span>
                                    <?php 

        $SQL_SELECT_VDOTYPE = "SELECT * FROM ag_vdotype ORDER BY vdo_typeid desc";
        $result = mysql_query($SQL_SELECT_VDOTYPE);
        while ( $rs = mysql_fetch_array( $result ) ) //นำค่าี่ที่ผ่านการคิวรี่จากตัวแปร $result มาทำการวนลูปเพื่อเอาค่าในแต่ละฟิลด์ออกมาโชว์แสดงผล
	{ 
			$vdo_typeid = $rs[vdo_typeid];									
			$vdo_type = $rs[vdo_type];	
			
			$SQL_SELECT_VDOTYPEDETAIL = "SELECT * FROM ag_vdotypedetail WHERE vdo_id=$vdo_id and vdo_typeid=$vdo_typeid ";	
			$result_typedetail = mysql_query($SQL_SELECT_VDOTYPEDETAIL);											
			$num_rows_s=mysql_num_rows($result_typedetail);
			if($num_rows_s == 1) echo $vdo_type."&nbsp;&nbsp;";
	}
	?></td>
                              </tr>
                              <tr>
                                <td height="20" align="left" class="style28"><span class="style8">ชื่อชุด :</span> <span class="style26"><?echo"$vdo_series_name";?></span></td>
                                <td width="35%" height="20" align="left" class="style28"><span class="style8">จำนวนผู้ใช้บริการ  :</span> <span class="style24"><?echo"$vdo_view";?></span></td>
                              </tr>
                              <tr>
                                <td height="20" align="left" class="style28"><span class="style8">ชื่อเรื่อง :</span> <a href="vdo_player.php?id=<?=$vdo_id?>" target="_self"><?echo"$vdo_name";?></a>
                                    <?php if($resultday2 <= 30) echo "<img src='pic/new.gif' />"; ?></td>
                                <td width="35%" height="20" align="left" class="style28"><span class="style8">ระดับความสนใจ  :</span> <span class="style24"><img src="pic/star_<?=$rating?>.gif" width="50" /></span></td>
                              </tr>
                              <tr>
                                <td height="20" align="left" class="style28"><span class="style26"><span class="style8">คำอธิบาย :</span> <? echo substr("$vdo_desc",0,200)."..."; ?></span></td>
                                <td width="35%" height="20" align="left" class="style28"><span class="style8">จำนวนผู้โหวต :</span> <span class="style24"><?echo"$votecount";?></span></td>
                              </tr>
                              <tr>
                                <td height="20" align="left" class="style28"><span class="style8">คำสำคัญ :</span> <span class="style24">
                                  <? 
	  if($vdo_keyword != ""){for ($i=0;$i<count($vdo_keyword_array);$i++)
	  {echo "<a href='$_SERVER[SCRIPT_NAME]?txtfield=2&txtkeyword=$vdo_keyword_array[$i]' target='_self'>$vdo_keyword_array[$i]</a>"." ";}  
	  }else echo "-"; 
	  ?>
                                  <?php //echo "$vdo_cover_word" 
	  
	  if($vdo_cover == ""){$vdo_cover = "pic/unknow_icon.jpg";}
	  ?>
                                </span></td>
                                <td width="35%" height="20" align="left" class="style28"><span class="style8">ผลการประเมิน</span><span class="style8"> :</span> <a href="vdo_evaluate_result.php?id=<?=$vdo_id?>&amp;vdo_name=<?=$vdo_name?>" target="_self"><? echo "$evalink"; ?></a></td>
                              </tr>
                              <tr>
                                <td height="20" align="left" class="style28"><span class="style8">หน่วยงาน / ชื่อผู้แต่ง :</span> <span class="style26"><?echo"$vdo_author";?></span></td>
                                <td width="35%" height="20" align="left" class="style28"><span class="style8">ประเภทไฟล์</span> :<span class="style26"> <img src='pic/<?=$vdo_pic?>' width='16'  border='0' align="middle" /></span></td>
                              </tr>
                              <tr>
                                <td height="20" align="left" class="style28"><span class="style26"><span class="style8">ความยาว :</span> <?echo"$vdo_length";?></span></td>
                                <td width="35%" height="20" align="left" class="style28">&nbsp;</td>
                              </tr>
                              <tr>
                                <td align="left" class="style28"><span class="style8">ปีที่จัดทำ :</span> <span class="style26"><?echo"$vdo_year";?></span></td>
                                <td width="35%" align="left" class="style28">&nbsp;</td>
                              </tr>
                            </table>
                            <span class="style19 style19">                          </span>
                            <hr />
                            <span class="style19 style19">
                            <? 
$a++; 
$i++;
} 
echo"<br>";


  
    mysql_close();
 
     
    ?>
                            </span></td>
                      </tr>
                    </table>
                    <p>&nbsp;</p>              </td>
          </tr>
          <tr>
            <td height="25" colspan="2" bgcolor="#CCFF00">&nbsp;</td>
          </tr>
        </table></td>
        <td width="25" align="right" background="img/tb/tb_right.jpg">&nbsp;</td>
      </tr>
      <tr>
        <td width="25" height="25" background="img/tb/tb_left_foot.jpg">&nbsp;</td>
        <td height="25" background="img/tb/tb_foot.jpg">&nbsp;</td>
        <td width="25" height="25" background="img/tb/tb_right_foot.jpg">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td width="1024" align="center" valign="bottom"><table width="50%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="25">&nbsp;</td>
      </tr>
    </table>
        <table width="1024" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="50"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="25" height="25" background="img/tb/tb_left_top.jpg">&nbsp;</td>
                  <td background="img/tb/tb_top.jpg">&nbsp;</td>
                  <td width="25" height="25" background="img/tb/tb_right_top.jpg">&nbsp;</td>
                </tr>
                <tr>
                  <td width="25" align="left" background="img/tb/tb_left.jpg">&nbsp;</td>
                  <td height="25" align="center" valign="middle" bgcolor="#CCFF00"><table width="96%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td height="25" align="center"><strong>ศูนย์ความรู้ด้านการเกษตร สำนักหอสมุด มหาวิทยาลัยเกษตรศาสตร์</strong></td>
                      </tr>
                  </table></td>
                  <td width="25" align="right" background="img/tb/tb_right.jpg">&nbsp;</td>
                </tr>
                <tr>
                  <td width="25" height="25" background="img/tb/tb_left_foot.jpg">&nbsp;</td>
                  <td background="img/tb/tb_foot.jpg">&nbsp;</td>
                  <td width="25" height="25" background="img/tb/tb_right_foot.jpg">&nbsp;</td>
                </tr>
            </table></td>
          </tr>
      </table></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
